#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define px first
#define py second

inline int read(){
	int x = 0; bool f = 0;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-') f = 1;
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = (x << 3) + (x << 1) + c - 48;
		c = getchar();
	}
	return f ? -x : x;
}

const ll inf = 1e18;
const int N = 1000005;
int n, c, cnt, top, cntx, k[N], stk[N], bar[N], lst[N], barx[N]; 
ll b[N], val[N];
vector<int> ans, a[N], v[N];

struct ARRAY{
	ll tr[N];
	inline void init(){memset(tr, 0, sizeof tr);}
	inline void modify(int l, int r, ll val){
		if(l > r) return;
		tr[l] += val; tr[r + 1] -= val;
	}
	inline void getans(int op){
		for(int i = 1; i < N; i ++) tr[i] += tr[i - 1];
		for(int i = 1; i <= cntx; i ++){
			if(! op) val[i] += tr[i];
			else val[i] += 1ll * barx[i] * tr[i]; 
		}
	}
};
ARRAY t1, t2;

int main(){
	freopen("list.in", "r", stdin);
	freopen("list.out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i ++){
		k[i] = read(); int rec = 0;
		for(int x, j = 1; j <= k[i]; j ++){
			x = read(); a[i].pb(x); bar[++ cnt] = x;
			if(! rec){rec = x; continue;}
			barx[++ cntx] = x - rec + 1; rec = x;
		}
	}
	barx[++ cntx] = 1;	 
	sort(barx + 1, barx + cntx + 1);
	cntx = unique(barx + 1, barx + cntx + 1) - barx - 1;
	sort(bar + 1, bar + cnt + 1);
	cnt = unique(bar + 1, bar + cnt + 1) - bar - 1;
	for(int i = 1; i <= n; i ++){
		for(auto t: a[i]){
			int p = lower_bound(bar + 1, bar + cnt + 1, t) - bar;
			v[p].pb(i);
		}
	}
	c = read(); for(int i = 1; i <= n; i ++) b[i] = read(), b[i] *= 1ll * i;
	int tt = 0;
	for(int i = 1; i <= n; i ++) if(k[i]) tt ++;
	t1.init(); t2.init();
	t2.modify(1, cntx, 1ll * tt * c);
	for(int i = 1; i <= cnt; i ++){
		int now = 0; top = 0;
		for(auto id: v[i]){
			if(! lst[id]){lst[id] = bar[i]; now ++; continue;}
			stk[++ top] = bar[i] - lst[id]; lst[id] = bar[i];
		}
		sort(stk + 1, stk + top + 1);
		ll pre = 0; int rec = 0;
		for(int j = 1; j <= top; j ++){
			if(stk[j] == stk[j - 1]){pre += 1ll * stk[j]; continue;}
			int p = upper_bound(barx + 1, barx + cntx + 1, stk[j]) - barx - 1;
			ll tmp = b[now + top - j + 1] + 1ll * c * pre;
			t1.modify(rec + 1, p, tmp); t2.modify(rec + 1, p, 1ll * (top - j + 1) * c);
			rec = p; pre += 1ll * stk[j];
		}
		rec ++;
		if(rec <= cntx){
			ll tmp = b[now] + 1ll * c * pre;
			t1.modify(rec, cntx, tmp);
		}
	}
	t1.getans(0); t2.getans(1);
	ll mn = inf;
	for(int i = 1; i <= cntx; i ++){
		if(val[i] < mn){mn = val[i]; ans.clear(); ans.pb(barx[i]);}
		else if(val[i] == mn) ans.pb(barx[i]);
	}
	printf("%lld %d\n", mn, (int)ans.size());
	for(auto x: ans) printf("%d ", x); return 0;
}
